﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using PsychveyApp1.classes;

namespace PsychveyApp1
{
    public partial class UserEditAccount : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                lblUsernameMyAccount.Text = (string)(Session["username"]);

                UserAccount currentUser = (UserAccount)(Session["currentUser"]);
                //lblPlanType.Text = currentUser.accountTypeSelected;
                //lblExpiryDateForPremium.Text = currentUser.expirationDateForPremium;
                //lblUsername.Text = currentUser.username;
                //tbxPassword.Text = currentUser.password;
                //tbxFullName.Text = currentUser.userFullName;
                //lblEmail.Text = currentUser.email;

                lblPlanType.Text = DBManager.GetAccountType(lblUsernameMyAccount.Text);
                lblExpiryDateForPremium.Text = DBManager.GetExpirationDateForPremium(lblUsernameMyAccount.Text);
                lblUsername.Text = DBManager.GetUsername(lblUsernameMyAccount.Text);
                tbxPassword.Text = DBManager.GetPassword(lblUsernameMyAccount.Text);
                tbxFullName.Text = DBManager.GetFullName(lblUsernameMyAccount.Text);
                lblEmail.Text = DBManager.GetEmailByUsername(lblUsernameMyAccount.Text);


                
            }
        }

        protected void ddlUser_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        protected void btnProceed_Click(object sender, EventArgs e)
        {
             if (ddlUser.SelectedIndex == 1)
            {
                Response.Redirect("UserAccountHome.aspx");

            }
            else if (ddlUser.SelectedIndex == 2)
            {
                Response.Redirect("Home.aspx");
            }
        }

        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            UserAccount update = new UserAccount();
            update.accountTypeSelected = lblPlanType.Text;
            update.expirationDateForPremium = lblExpiryDateForPremium.Text;
            update.username = lblUsername.Text;
            update.password = tbxPassword.Text;
            update.userFullName = tbxFullName.Text;
            update.email = lblEmail.Text;
            DBManager.UpdateUser(update);
            Session["updatedUser"] = update;
            Response.Redirect("UserEditedDetails.aspx");
        }

        protected void AdminLoginShortcut_Click(object sender, EventArgs e)
        {
            Response.Redirect("AdminLogin.aspx");
        }

    }
}